//
// Created by haoy on 2017/3/16.
//

#ifndef RECORD_TIMESTAMP_HPP
#define RECORD_TIMESTAMP_HPP

#include <stdint.h>

#include "mod/rtp/RTPPacket.h"

class Timestamp {

    class Base {
    public:
        uint32_t rtp_ts;
        uint64_t clock_ms;
    };

    class BaseList {
    public:
        int calc(uint32_t rtp_ts, uint64_t ms, uint32_t clockrate, uint64_t& pts);
        void update(uint32_t rtp_ts, uint64_t ms);
        void dump() const;
    private:
        std::map<uint32_t, Base> _bases;
    };

public:
    void updateNTP(uint32_t ssrc, uint32_t rtp_ts, uint64_t clock_usec);
    int calculatePts(RTPPacket *p, uint64_t& pts);
    void dump() const;
private:
    // ssrc1 -> rtp_ts -> Base
    std::map<uint32_t, BaseList> _base;
    // first rtp timestamp
    std::map<uint32_t, uint32_t> _clockrate;
    std::map<uint32_t, uint64_t> _last_pts;

};


#endif //RECORD_TIMESTAMP_HPP
